<?php
namespace Face\Controller;
class PingController extends CommonController {
    /*接收评论*/
    public function index()
    {
        $post = i('post.');
        if(IS_POST){
            if(trim(empty($post['pinglun']))) {
                $_SESSION['kong'] = '评论有误，请检查输入';
                $this->redirect('Face/Ping/kong');
            }
            $data = [
                'openid'=>$_SESSION['wechatopenid'],
                'name'=>$_SESSION['wechatname'],
                'time'=>time(),
                'goodid'=>$post['shangpinid'],
                'text'=>$post['pinglun'],
                'headimg'=>$_SESSION['wechatimg']
            ];
            if(M('pinglun')->add($data)){
                $this->redirect('Face/Index/content',array('id'=>$post['shangpinid']));
            }else{
                $_SESSION['kong'] = '评论有误，请检查输入';
                $this->redirect('Face/Ping/kong');
            }
        }
    }
    /*评论有误*/
    public function kong()
    {
        $this->display();
    }
}